﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data.Common;
using System.Data;

namespace OPTFleet.Data
{
    class GestaoContas
    {
        private Conexao sqlConnection;
        public Conexao SqlConnection
        {
            set { sqlConnection = value; }
        }

        public GestaoContas()
        {
            this.sqlConnection = new Conexao();
            this.sqlConnection.connect();
        }


        public String VerificaConta(string username, string password)
        {
            SqlConnection sqlCon;
            SqlCommand sqlCmd;
            String stmtSql,ret;

            sqlCon = (SqlConnection)sqlConnection.Connection;

            stmtSql = "SELECT tipoconta FROM contas WHERE utilizador = @UserName AND password = @Password";

            sqlCmd = new SqlCommand(stmtSql,sqlCon);
            sqlCmd.Parameters.Add("@UserName", SqlDbType.NChar);
            sqlCmd.Parameters["@UserName"].Value = username;
            sqlCmd.Parameters.Add("@Password", SqlDbType.NChar);
            sqlCmd.Parameters["@Password"].Value = password;


            ret = (String)sqlCmd.ExecuteScalar();

            if (ret != null)
                ret.Trim();

            return ret;
        }
    }
}
